using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Home.Haushalt
{
    /// <summary>
    /// 
    /// </summary>
    public partial class JournalFormDetails : Form
    {
        /// <summary></summary>
        private DataGridView _journalGrid;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="journalGrid"></param>
        public JournalFormDetails(DataGridView journalGrid)
        {
            InitializeComponent();

            _journalGrid = journalGrid;

            if (_journalGrid.SelectedRows.Count > 0)
            {
                ShowLog(_journalGrid.SelectedRows[0]);
            }
            else
            {
                MessageBox.Show("Selektion ist nicht gefunden");
                Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="selectedRow"></param>
        private void ShowLog(DataGridViewRow selectedRow)
        {
            lblStatus.Text = selectedRow.Cells[Journal.COLUMNNAME_ACTIONRESULT].Value.ToString();
            lblModul.Text = selectedRow.Cells[Journal.COLUMNNAME_SENDER].Value.ToString();
            lblAction.Text = selectedRow.Cells[Journal.COLUMNNAME_ACTION].Value.ToString();
            txtComment.Text = selectedRow.Cells[Journal.COLUMNNAME_COMMENTS].Value.ToString();
            txtException.Text = selectedRow.Cells[Journal.COLUMNNAME_EXCEPTION].Value.ToString();

            btnNext.Enabled = (selectedRow.Index + 1 < _journalGrid.Rows.Count);
            btnPrev.Enabled = (selectedRow.Index  > 0);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNext_Click(object sender, EventArgs e)
        {
            DataGridViewRow selectedRow = _journalGrid.SelectedRows[0];
            _journalGrid.ClearSelection();

            _journalGrid.Rows[selectedRow.Index + 1].Selected = true;

            ShowLog(_journalGrid.Rows[selectedRow.Index + 1]);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrev_Click(object sender, EventArgs e)
        {
            DataGridViewRow selectedRow = _journalGrid.SelectedRows[0];
            _journalGrid.ClearSelection();

            _journalGrid.Rows[selectedRow.Index - 1].Selected = true;

            ShowLog(_journalGrid.Rows[selectedRow.Index-1]);
        }

    }
}